<template>
    <div>
        <h3>科室添加</h3>
        <table>
            <thead>
                <tr>
                    <td>科室名称</td>
                    <td><input type="text" v-model="info.fName" ></td>
                </tr>

                <tr>
                    <td>科室人数</td>
                    <td><input type="text" v-model="info.kCount" ></td>
                </tr>

                <tr>
                    <td>所属科室</td>
                    <td><select v-model="info.kid">
                        <option value="">请选择</option>
                        <option :value="o.kid" v-for="o in Ken">{{ o.kName }}</option>
                    </select></td>
                </tr>

                
                <tr>
                    <td>科室描述</td>
                    <td><textarea v-model="info.kText"></textarea></td>
                </tr>

                <tr>
                    <td>创造时间</td>
                    <td><input type="date" v-model="info.kDate"></td>
                </tr>
                
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="Add"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();

const Tifand=()=>{
    router.push({
        path:"/showk",
    })
}

onMounted(()=>{
    List();
})

let info:any=ref({
  "fName": "",
  "kCount": "",
  "kid": "",
  "kText": "",
  "kDate": "",
  "isDell": 0
});

const Add=()=>{
    if(info.value.fName=="" )
{
    alert("科室名称不为空");
    return;
}
    if(info.value.kCount=="" )
{
    alert("科室人数不为空");
    return;
} 
    if(info.value.kid=="" )
{
    alert("所属科室不为空");
    return;
}
    if(info.value.kText=="" )
{
    alert("科室描述不为空");
    return;
} 
    if(info.value.kDate=="" )
{
    alert("创造时间不为空");
    return;
}
    axios({
        url:"https://localhost:7030/api/User/AddK",
        method:'post',
        data:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1 )
    {
        alert("科室名称存在");
        return;
    }
    
        if(res.data>0 )
    {
        alert("添加成功");
        Tifand();
    }
    })


}

let Ken:any=ref([]);

const List=()=>{
    axios({
        url:"https://localhost:7030/api/User/ListK",
        method:'get',
    })

    .then((res)=>{
        console.log(res);
        Ken.value=res.data;
    })
}



</script>

<style scoped>

</style>